#include<cstdio>
#include<cstring>
using namespace std;
char s[10],ad[100];
int n,id[100000][6],cnt;
bool chuli(char *a)
{
	int len=strlen(a),x=0;
	for(int i=0;i<len;i++){
		if(a[i]<'0'||a[i]>'9'){
			printf("ERR\n");
			return 0;
		}
		if(a[i]=='0'){
			if(a[i+1]!='.'){
				printf("ERR\n");
				return 0;
			}
		}
		int sum=0;
		while(a[i]>='0'&&a[i]<='9'){
			sum=sum*10+a[i]-48;
			i++;
		}
		if(x==3){
			id[cnt][x++]=sum;
			if(a[i]==':'){
				i++;
				if(a[i]<'0'&&a[i]>'9'){
					printf("ERR\n");
					return 0;
				}
				if(a[i]=='0'){
					if(a[i+1]!='.'){
						printf("ERR\n");
						return 0;
					}
				}
				int Sum=0;
				while(a[i]>='0'&&a[i]<='9'){
					Sum=Sum*10+a[i]-48;
					i++;
				}
				if(Sum>=0&&Sum<=65536){
					id[cnt][x++]=Sum;
				}
				else{
					printf("ERR\n");
					return 0;
				}
			}
		}
		else{
			if(a[i]!='.'){
				printf("ERR\n");
				return 0;
			}
			else{
				if(sum>=0&&sum<=255)
					id[cnt][x++]=sum;
				else{
					printf("ERR\n");
					return 0;
				}
			}
		}
	}
	cnt++;
	return 1;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s%s",s,ad);
		if(s[0]=='S'){
			if(chuli(ad)){
				id[cnt-1][5]=i;
				int x=0;
				for(int k=0;k<cnt-1;k++){
					int f=0;
					for(int j=0;j<5;j++){
						if(id[k][j]!=id[cnt-1][j]){
							f=1;
						}
					}
					if(!f){
						printf("FAIL\n");
						cnt--;
						x=1;
						break;
					}
				}
				if(x){
					continue;
				}
				printf("OK\n");
			}
//			for(int i=0;i<5;i++)
//				printf("%d ",id[cnt-1][i]);
//			printf("\n");
		}
		if(s[0]=='C'){
			if(chuli(ad)){
				int x=0;
				for(int k=0;k<cnt-1;k++){
					int f=0;
					for(int j=0;j<5;j++){
						if(id[k][j]!=id[cnt-1][j]){
							f=1;
						}
					}
					if(!f){
						printf("%d\n",id[k][5]);
						x=1;
						break;
					}
				}
				if(!x){
					printf("FAIL\n");
				}
				cnt--;
			}
		}
	}
	return 0;
}
